package com.xxl.job.admin.service.impl;

import com.xxl.job.admin.core.thread.JobCompleteHelper;
import com.xxl.job.admin.core.thread.JobRegistryHelper;
import com.xxl.job.admin.core.thread.JobTriggerPoolHelper;
import com.xxl.job.admin.core.trigger.TriggerTypeEnum;
import com.xxl.job.admin.service.XxlJobService;
import com.xxl.job.core.biz.AdminBiz;
import com.xxl.job.core.biz.model.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author xuxueli 2017-07-27 21:54:20
 */
@Service
public class AdminBizImpl implements AdminBiz {

    @Resource
    private XxlJobService xxlJobService;

    @Override
    public ReturnT<String> callback(List<HandleCallbackParam> callbackParamList) {
        return JobCompleteHelper.getInstance().callback(callbackParamList);
    }

    @Override
    public ReturnT<String> registry(RegistryParam registryParam) {
        return JobRegistryHelper.getInstance().registry(registryParam);
    }

    @Override
    public ReturnT<String> registryRemove(RegistryParam registryParam) {
        return JobRegistryHelper.getInstance().registryRemove(registryParam);
    }

    @Override
    public ReturnT<String> addJob(XxlJobInfo jobInfo) {
        return xxlJobService.add(jobInfo);
    }

    @Override
    public ReturnT<String> updateJob(XxlJobInfo jobInfo) {
        return xxlJobService.update(jobInfo);
    }

    @Override
    public ReturnT<String> removeJob(JobIdReq jobIdReq) {
        return xxlJobService.remove(jobIdReq.getJobId());
    }

    @Override
    public ReturnT<String> startJob(JobIdReq jobIdReq) {
        return xxlJobService.start(jobIdReq.getJobId());
    }

    @Override
    public ReturnT<String> stopJob(JobIdReq jobIdReq) {
        return xxlJobService.stop(jobIdReq.getJobId());
    }

}
